Attribute VB_Name = "mHook"
Option Explicit

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CANCELJOURNAL = &H4B

Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Type TMSG
    hwnd As Long
    Message As Long
    wParam As Long
    lParam As Long
    Time As Long
    PT As POINTAPI
End Type

Public hJouHook As Long, hAppHook As Long, lpHooker As Long

Public Function JouHookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If nCode < 0 Then
        JouHookProc = CallNextHookEx(hJouHook, nCode, wParam, lParam)
        Exit Function
    End If

    Call CallEvent(lpHooker, lParam)
    Call CallNextHookEx(hJouHook, nCode, wParam, lParam)
End Function

Public Function AppHookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If nCode < 0 Then
        AppHookProc = CallNextHookEx(hAppHook, nCode, wParam, lParam)
        Exit Function
    End If

    Dim msg As TMSG
    CopyMemory msg, ByVal lParam, Len(msg)

    Select Case msg.Message
        Case WM_CANCELJOURNAL
            If wParam = 1 Then Call CallEvent(lpHooker, WM_CANCELJOURNAL)
    End Select
    Call CallNextHookEx(hAppHook, nCode, wParam, ByVal lParam)
End Function

Private Sub CallEvent(ByVal lpObj As Long, ByVal lParam As Long)
'    Dim Hooker As Hooker
'    CopyMemory Hooker, lpObj, 4&
'    Hooker.CallEvent lParam
'    CopyMemory Hooker, 0&, 4&
End Sub

